
<form method="post" action="/oss/?r=announcement/doAdd">
    <{include file='../common_params.tpl'}>

    <div class="box box-black">
        <div class="box-body">
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 20%;"></col>
                    <col style="width: 80%;"></col>
                </colgroup>

                <tr>
                    <th class="th-label">服务器</th>
                    <td>
                        <select class="form-control" name="server">
                            <{html_options options=$serverList selected=$server}>
                        </select>
                    </td>
                </tr>

                <tr>
                    <th class="th-label">公告标题</th>
                    <td>
                        <input type="text" class="form-control" name="title" />
                    </td>
                </tr>

                <tr>
                    <th class="th-label-s">显示情况</th>
                    <td>
                        <label><input name='isPopUpEveryLogin' type="checkbox" /> 每次登陆都显示</label>
                        <label><input name='isPopUpFirstLogin' type="checkbox" checked /> 第一次登陆时显示</label>
                    </td>
                </tr>

                <tr>
                    <th class="th-label">版本号</th>
                    <td>
                        <input type="text" class="form-control" name="version" />
                    </td>
                </tr>

                <tr>
                    <th class="th-label">公告内容</th>
                    <td>
                        <textarea class="form-control" rows="5" name="content"></textarea>
                    </td>
                </tr>

                <tr>
                    <th class="th-label">公告详情</th>
                    <td>
                        <table class="table table-bordered">
                            <colgroup>
                                <col style="width: 30%;"></col>
                                <col style="width: 60%;"></col>
                                <col style="width: 10%;"></col>
                            </colgroup>
                            <tr>
                                <th style="background: #f5f5f5; text-align: center;">标题</th>
                                <th style="background: #f5f5f5; text-align: center;">正文</th>
                                <th style="background: #f5f5f5; text-align: center;">操作</th>
                            </tr>
                            <tr>
                                <th><input type="text" name="item_title[]" class="form-control" /></th>
                                <th><input type="text" name="item_content[]" class="form-control" /></th>
                                <th>
                                    <div style="width: 50%; margin: 8px auto;">
                                        <a class="pull-left insert-item" href="javascript:;"><i class="fa fa-plus"></i></a>
                                        <a class="pull-right delete-item" href="javascript:;"><i class="fa fa-minus"></i></a>
                                    </div>
                                </th>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <th class="th-label">公告生效时间</th>
                    <td>
                        <input type="text" name="date" class="form-control inline time" placeholder="" />
                    </td>
                </tr>

                <tr>
                    <th class="th-label">有效时间</th>
                    <td>
                        <input type="text" name="validity" class="form-control inline" placeholder="公告生效时长,单位(秒)" />
                        秒
                    </td>
                </tr>

            </table>
        </div>

        <div class="box-footer">
            <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
            <button type="submit" class="btn btn-default pull-right">保存</button>
        </div>
    </div>
</form>

<script>
    $(function(){
        $(".time").datetimepicker({
            format: 'yyyy-mm-dd hh:ii:00',
        });

        $("#sel-end-type").change(function(){
            var val = $(this).val();
            if(val == 1) {
                $(".end-by-num").hide();
                $(".end-by-time").show();
            }else if (val == 2) {
                $(".end-by-time").hide();
                $(".end-by-num").show();
            }else if (val == 3) {
                $(".end-by-time,.end-by-num").hide();
            }
        }).change();

        $(".insert-item").live('click', function(){
            var tr = $(this).closest('tr'),
                cloneTr = tr.clone();

            cloneTr.find("input[name]").val('');

            cloneTr.insertAfter(tr);
        });

        $(".delete-item").live('click', function(){
            var tr = $(this).closest('tr'),
                table = tr.closest('table');

            if(table.find('tr').length > 2){
                tr.remove();
            }else{
                tr.find("input[name]").val('');
            }
        });
    });
</script>